package com.infinity.springboot.thymeleaf.controller;

import com.infinity.springboot.thymeleaf.model.User;
import com.infinity.springboot.thymeleaf.service.UserService;
import com.infinity.springboot.thymeleaf.service.impl.UserServiceImpl;
import com.infinity.springboot.thymeleaf.vo.ResultBean;
import com.infinity.springboot.thymeleaf.vo.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: wuxiang
 * @Description:
 * @Date: Create in 2020/6/16 20:41
 */

@RequestMapping("v1/user")
@RestController
public class UserController extends BaseController{



    @Autowired
    private UserService userService;

    /**
     * 用户详情
     * @param userId
     * @return
     */
    @GetMapping
    public ResultBean getUser(Integer userId){
        User user = userService.getUser(userId);
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user,userVo);
        return ResultBean.ok(userVo);
    }


    /**
     * 用户列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/{page}/{size}")
    public ResultBean getUserList(@PathVariable("page") int page,@PathVariable("size") int size){

        return ResultBean.ok();
    }

    /**
     * 修改用户
     * @param userVo
     * @return
     */
    @PostMapping
    public ResultBean updateUser(UserVo userVo){

        return ResultBean.ok();
    }


    /**
     * 删除用户
     * @param userId
     * @return
     */
    @DeleteMapping
    public ResultBean delete(Integer userId){

        return ResultBean.ok();
    }


    /**
     * 增加用户
     * @param user
     * @return
     */
    @PutMapping
    public ResultBean add(User user){

        return ResultBean.ok();
    }
}
